<%@ page import="java.util.Map"%>
<%@ page import="com.hospital.util.DbUtil"%>
<%@ page import="com.hospital.util.Pagination"%>
<%@ page import="com.hospital.model.*"%>
<%@ page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="images/main.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/trim.js"></script>
<script language="javascript" type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<title></title>
<script type="text/javascript">
	function sub(){
		var mname = document.getElementById("mname");
		if(trim(mname.value).length == 0){
			alert("药品名称关键字不能为空。");
			mname.focus();
		}else{
			window.location.href = "search_info_medicinename_list.jsp?mname=" + mname.value;;
		}
	}
</script>
</head>
<body>
	<jsp:include page="right_top.jsp"></jsp:include>
	<!-- TOP START -->
	<div id="right_font">
		<img src="images/main_14.gif" /> 您现在所在的位置：首页 &rarr; 药品信息查询 &rarr; <span
			class="bfont">药品模糊查询</span>
	</div>
	<!-- TOP END -->
	
	<!-- MAIN START -->
	<form action="" method="post" name="form" id="form">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr height="30px;" background="#c9c9c9">
				<td>
					<font color="#FF0000">*</font>请输入药品名称关键字： 
					<input type="text" name="mname" id="mname"/>
					<input type="button" value="提交" onclick="sub();"/>
					<input type="button" value="返回" onclick="history.go(-1);"/>
				</td>
			</tr>
			<tr>
				<td>
					<!-- table context start -->
					<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c9c9c9">
						<tr>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">编号</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">药品名称<br></span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">药品记录号<br></span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">药品到期时间<br></span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">药品剩余量<br></span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">所在库房<br></span></strong>
								</div>
							</td>
						</tr>
						<%
							/**
							 * 分页begin
							 */
							final int pageSize = 15; // 一页显示 15 条记录
		
							int pageNum = 1; // 当前页数
							int pageCount = 1; // 总页数
		
							int recordCount = 0; // 总记录数
		
							String strAbsPath = application.getRealPath(request.getRequestURI()); // 获得当前文件的绝对路径名
							int endIndex = strAbsPath.length();
							int beginIndex = strAbsPath.lastIndexOf("\\") + 1;
							String pageUrl = strAbsPath.substring(beginIndex, endIndex); // 获取当前文件名，如：xxx.jsp,或者 xxx.html
		
							try {
								// 从地址栏参数取当前页数
								if (request.getParameter("pageNum") == null) {
									pageNum = 1;
								} else {
									pageNum = Integer.parseInt(request.getParameter("pageNum"));
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
							String mname = request.getParameter("mname");
							String sql_search_mname = "select * from t_medicinename where mname like '%%%%%%%%%%"+mname+"%%%%%%%%%'";
							List<Map<String, Object>> list_search_mname = DbUtil.find(sql_search_mname);
							recordCount = list_search_mname.size();
							// 计算总页数
							pageCount = (recordCount + pageSize - 1) / pageSize;
							// 本页从 startRecord 行开始
							int startRecord = (pageNum - 1) * pageSize;
							/**
							 * 分页end
							 */
							int num = 1;
							Map<String, Object> map_search_mname = null;
							for (int ii = 0; ii < list_search_mname.size(); ii++) {
								map_search_mname = (Map<String, Object>)list_search_mname.get(ii);
								int ypmc = (Integer)map_search_mname.get("id");
								String sql = "select * from t_stroage where ypmc = "+ypmc+" order by id desc limit " + startRecord + " ," + pageSize;
								List<Map<String, Object>> list = DbUtil.find(sql);
								Map<String, Object> map = null;
								for (int i = 0; i < list.size(); i++) {
									map = (Map<String, Object>)list.get(i);
						%>
						<tr>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=num++%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map_search_mname.get("mname")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("ypmc")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("dqrq")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">&nbsp;
								<span class="STYLE3"><%=map.get("ypsysl")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">&nbsp;
								<span class="STYLE3"><%=map.get("yplb")%></span>
								</div>
							</td>
						</tr>
						<%
								}
							}
						%>
					</table>
				<!-- table context end -->
				</td>
			</tr>
			<tr>
				<td height="35">
					<!-- page start -->
					<table width="100%" border="0" cellspacing="0" cellpadding="1">
						<tr>
							<td width="75%" valign="top" class="STYLE1">
								<div align="right">
									<%=Pagination.getPagination(pageNum, pageCount, recordCount,pageUrl)%>&nbsp;&nbsp;
								</div>
							</td>
						</tr>
					</table>
					<!-- page end -->
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
